#include "clerk_manage_withdraw_apply_dialog.h"
#include "ui_clerk_manage_withdraw_apply_dialog.h"
#include "QSqlDatabase"
#include "QDebug"
#include "QSqlQuery"
#include "QVariant"
#include "QComboBox"
#include "deposit_info.h"
#include "bts_mgmt.h"
#include "QMessageBox"

clerk_manage_withdraw_apply_dialog::clerk_manage_withdraw_apply_dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::clerk_manage_withdraw_apply_dialog)
{
    ui->setupUi(this);
    this->setWindowTitle("取款审核");
}

clerk_manage_withdraw_apply_dialog::~clerk_manage_withdraw_apply_dialog()
{
    delete ui;
}

void clerk_manage_withdraw_apply_dialog::on_confirm_clicked()
{
    if(ui->comboBox->currentText() == "已通过")
    {
        //更新存款信息为未储蓄状态，而不是直接删除
        QSqlDatabase sqlite_dep = QSqlDatabase::database("deposit");
        QSqlQuery query_dep(sqlite_dep);
        query_dep.prepare("UPDATE DEPOSIT SET savingstype = ?, savingsamount = ?, savingstime = ? WHERE custtelnumber = ? ");
        query_dep.addBindValue("未进行储蓄");
        query_dep.addBindValue("未进行储蓄");
        query_dep.addBindValue("未进行储蓄");
        query_dep.addBindValue(ui->cust_card_id->text());
        query_dep.exec();

        QSqlDatabase sqlite_wd = QSqlDatabase::database("withdraw");
        QSqlQuery query_wd(sqlite_wd);
        query_wd.prepare("UPDATE WITHDRAW SET reviewstatus = ? WHERE custtelnumber = ?");
        query_wd.addBindValue("已通过");
        query_wd.addBindValue(ui->cust_card_id->text());
        query_wd.exec();


        QMessageBox box;
        box.setWindowTitle("completed");
        box.setText("审核成功");
        box.setIcon(QMessageBox::Information);
        box.exec();
        return;
    }

    else return;
}
